﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MS.BasicData.Infrastructure;
using MS.BasicData.Read.API.Applications.UserInfos;

namespace MS.BasicData.Read.API.Controllers
{
    /// <summary>
    /// 用户控制器API
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class UserInfoController : ControllerBase
    {
        private readonly IMediator _mediator;

        private readonly UserDataDbconterxt _db;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        /// <param name="db"></param>
        public UserInfoController(IMediator mediator, UserDataDbconterxt db)
        {
            _mediator = mediator;
            _db = db;
        }

        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="register"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiRestult> AddUserInfos(RegisterRequestModel register)=> await _mediator.Send(register);
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="UserNick">用户昵称</param>
        /// <param name="Password">用户密码</param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<ApiRestult> UserLogin(string UserNick,string Password)
        {
            LoginRequestModel login = new LoginRequestModel
            {
                UserNick = UserNick,
                Password = Password
            };
            return await _mediator.Send(login);
        }

        /// <summary>
        /// 用户信息列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiRestult> GetListUserInfo([FromQuery]ListQueryRequestModel list)
        {
            return await _mediator.Send(list);
        }

        /// <summary>
        /// 用户信息逻辑删除
        /// </summary>
        /// <param name="UserInfoId"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiRestult> DeleteUserInfo(int UserInfoId)
        {
            DeleteRequestModel delete = new DeleteRequestModel
            {
                UserInfoId = UserInfoId
            };
            return await _mediator.Send(delete);
        }

        /// <summary>
        /// 用户信息修改
        /// </summary>
        /// <param name="update"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiRestult> UpdateUserInfo(UpdateRequestModel update)
        {
            return await _mediator.Send(update);
        }
    }
}
